<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #tableTitle>
        <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
        <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <template #overlay>
            <a-menu>
              <a-menu-item key="1" @click="batchHandleDelete">
                <Icon icon="ant-design:delete-outlined"></Icon>
                删除
              </a-menu-item>
            </a-menu>
          </template>
          <a-button>批量操作
            <Icon style="fontSize:12px" icon="ant-design:down-outlined"></Icon>
          </a-button>
        </a-dropdown>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getActions(record)"/>
      </template>


      <!-- 展示退款订单号 -->
      <template #refundOrderNo="{ record }">
        <Row :gutter="[24, 24]" class="order-no">
          <Col :span="4">
            <Tag color="blue">退款</Tag>
          </Col>
          <Col :span="20">
            <Tooltip placement="topLeft">
              <template #title>
                <span>{{ record.refundOrderId }}</span>
              </template>
              <span class="refund-order-no-data">{{ record.refundOrderId }}</span>
            </Tooltip>
          </Col>
        </Row>
        <Row :gutter="[24, 24]">
          <Col :span="4">
            <Tag color="green">商户</Tag>
          </Col>
          <Col :span="20">
            <Tooltip placement="topLeft">
              <template #title>
                <span>{{ record.mchRefundNo }}</span>
              </template>
              <span class="refund-order-no-data">{{ record.mchRefundNo }}</span>
            </Tooltip>
          </Col>
        </Row>
      </template>


      <!-- 展示支付订单号 -->
      <template #payOrderNo="{ record }">
        <Row :gutter="[24, 24]" class="order-no">
          <Col :span="4">
            <Tag color="blue">支付</Tag>
          </Col>
          <Col :span="20">
            <Tooltip placement="topLeft">
              <template #title>
                <span>{{ record.payOrderNo }}</span>
              </template>
              <span class="pay-order-no-data">{{ record.payOrderNo }}</span>
            </Tooltip>
          </Col>
        </Row>
        <Row :gutter="[24, 24]">
          <Col :span="4">
            <Tag color="green">渠道</Tag>
          </Col>
          <Col :span="20">
            <Tooltip placement="topLeft">
              <template #title>
                <span>{{ record.channelPayOrderNo }}</span>
              </template>
              <span class="pay-order-no-data">{{ record.channelPayOrderNo }}</span>
            </Tooltip>
          </Col>
        </Row>
      </template>
    </BasicTable>
    <DetailModal @register="register" />
  </div>
</template>
<script lang="ts" name="PayRefund" setup>

import {Col, Row, Tag, Tooltip} from 'ant-design-vue';
import {BasicTable, TableAction} from '/@/components/Table';
import {useDrawer} from '/@/components/Drawer';
import DetailModal from './DetailModal.vue';
import {useGlobSetting} from '/@/hooks/setting';
import {columns, searchFormSchema} from './refund.data';
import {getExportUrl, getImportUrl, getList} from './refund.api';
import {useListPage} from '/@/hooks/system/useListPage';
import {useMessage} from '/@/hooks/web/useMessage';
import {Icon} from '/@/components/Icon'

const { createMessage } = useMessage();
const glob = useGlobSetting();
const [register, { openDrawer: openDetail }] = useDrawer();
// 列表页面公共参数、方法
const { prefixCls, onExportXls, onImportXls, tableContext } = useListPage({
  designScope: 'PayFund',
  tableProps: {
    title: '退款订单列表',
    api: getList,
    columns: columns,
    actionColumn: {
      width: 100,
      title: '操作',
      dataIndex: 'action',
      fixed: 'right',
      slots: { customRender: 'action' },
    },
    formConfig: {
      schemas: searchFormSchema,
      fieldMapToTime: [['fieldTime', ['beginDate', 'endDate'], 'YYYY-MM-DD HH:mm:ss']],
    },
  },
  exportConfig: {
    name: "退款订单",
    url: getExportUrl,
  },
  importConfig: {
    url: getImportUrl
  }
})

const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;

/**
 * 查看
 */
function handleDetail(record) {
  openDetail(true, {
    record,
    isUpdate: true,
  });
}
/**
 * 操作列定义
 * @param record
 */
function getActions(record) {
  return [
    {
      label: '查看',
      onClick: handleDetail.bind(null, record),
      // ifShow: record.sendStatus == 0
    }
  ]
}

</script>


<style>
.order-no {
  margin-bottom: 5px;
}
.refund-order-no-data {
  float: left;
  text-align: left;
  width: 100%;
  overflow: hidden;
  margin-left: 5px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.pay-order-no-data {
  float: left;
  text-align: left;
  width: 160px;
  overflow: hidden;
  margin-left: 5px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

</style>
